<template>
  <el-dialog
    class="supporting-devices-dialog"
    width="574px"
    :visible="visible"
    :title="title"
    :before-close="handleClose"
  >
    <div style="height: 40vh;" class="flex-column">
      <el-tabs v-model="activeName" type="card" style="width: 544px;">
        <el-tab-pane
          v-for="({label,name},index) in tabs"
          :key="index"
          :label="label"
          :name="name"
        ></el-tab-pane>
      </el-tabs>
      <div class="flex-sub" style="max-height: 40vh;">
        <el-table
          :data="(value.find(({key})=>key===activeName)||{tableData:[]}).tableData"
          height="98%"
        >
          <el-table-column prop="name" label="名称"></el-table-column>
          <el-table-column prop="id" label="id"></el-table-column>
          <el-table-column prop="action" label="动作" align="center">
            <template v-slot="{row}">
              <div v-if="row.action==='people'" style=" text-align: right;" class="pd-right-10">
                <svg-icon icon-class="computer" class="people-icon"></svg-icon>
                <svg-icon icon-class="cellphone" class="people-icon"></svg-icon>
                <svg-icon icon-class="email" class="people-icon"></svg-icon>
              </div>
              <div v-if="row.action==='camera'" style=" text-align: right;">
                <svg-icon icon-class="picture" class="camera-icon"></svg-icon>
              </div>
              <div
                v-if="row.action==='robot'"
                style="color: #0084ee; text-align: right;cursor: pointer;"
              >
                前往跳转
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleClose">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
export default {
  name: 'SupportingDevicesDialog',
  props: {
    visible: {
      type: Boolean,
      required: true,
      default: false,
    },
    title: {
      title: String,
      required: true,
      default: '',
    },
    value: {
      type: Array,
      required: false,
      default: () => [
        {
          key: 'securityOfficer',
          name: '安保员',
          tableData: [],
        },
      ],
    },
  },
  data() {
    return {
      activeName: '',
    }
  },
  computed: {
    tabs() {
      return this.value.map((tab, index) => {
        if (index === 0) {
          this.activeName = tab.key
        }
        return {
          label: tab.name,
          name: tab.key,
        }
      })
    },
  },
  methods: {
    handleClose() {
      this.$emit('update:visible', false)
    },
  },
}
</script>

<style scoped lang="scss">
.supporting-devices-dialog {
  .content {
    height: 30vh;
  }

  .camera-icon {
    width: 23px;
    height: 17px;
  }

  .plain-box {
    display: inline-block;
    width: 40px;
    height: 22px;
    line-height: 20px;
    color: #666;
    text-align: center;
    border: 1px solid #666;
    border-radius: 2px;
  }

  .people-icon {
    width: vw(22px);
    height: vh(24px);
    margin: 0 vw(5px);
  }
}

::v-deep {
  .el-dialog__body {
    padding: 10px 20px;
  }

  .el-table__header-wrapper {
    display: none;
  }

  .el-table td,
  .el-table th.is-leaf {
    border-bottom: none;
  }
}
</style>
